//
//  OAaddresslistViewController.m
//  tongxiangOASystem
//
//  Created by michael on 2018/4/10.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "OAaddresslistViewController.h"
#import "OADepAddressController.h"

@interface OAaddresslistViewController ()

@end

@implementation OAaddresslistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
               self.title = @"科室列表";
    [self loaddata];

    // Do any additional setup after loading the view.
}
- (void)loaddata{
 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"path":_path}];
[HttpTools requestWithURL:KExchother arrays:array method:@"secdepTxlTree" success:^(id JSON) {
    NSLog(@"%@",JSON);
              [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

  
      _dataArray =   [NSMutableArray array];
        NSArray *array = JSON[@"data"];
 NSArray *pararray = array[0][@"Parent"];
         for (NSDictionary *dic in pararray) {
    NSDictionary *dict = dic;
    [_dataArray addObject:dict];
    
}
[self initview];
//[self initview];
//
//        [self.tableView reloadData];

 
        if (self.dataArray.count ==0) {
            [self.view makeToast:@"暂时还没数据哦"];
        }
    } failure:^(NSError *error) {
              [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

        
    }];
}
- (void)initview{
if (!_tableView) {
     _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 00, KScreenWidth,KScreenHeight-kTopHeight-LL_TabbarSafeBottomMargin) style:UITableViewStylePlain];

     self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//        self.tableView.backgroundColor = [UIColor colorWithHexString:@"efeff4"];
        self.tableView.backgroundColor = [UIColor whiteColor];
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
    
    
}

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  return  44;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头，距离右边有十几像素；

    }
    cell.imageView.image = [UIImage imageNamed:@"蓝"];
 NSDictionary *dic = self.dataArray[indexPath.row];
     cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.text =dic[@"bmxm"];
    return cell;


 }
 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    OAaddresslistViewController *depVC = [[OAaddresslistViewController alloc]init];
    OADepAddressController * depVC = (OADepAddressController*)[storyBoard instantiateViewControllerWithIdentifier:@"DepAddressID" ];
     NSDictionary * dict = self.dataArray[indexPath.row];
    depVC.path = _path;
        depVC.unid = dict[@"unid"];

                depVC.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:depVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
